//
//  SecViewController.m
//  Photo
//
//  Created by dllo on 16/7/20.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "SecViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height


@interface SecViewController () <UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *photoScrollView;
@property (nonatomic, strong) UIScrollView *smallScrollView;
@end

@implementation SecViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.photoScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    self.photoScrollView.contentSize = CGSizeMake(WIDTH * 8, 0);
    self.photoScrollView.delegate = self;
    self.photoScrollView.pagingEnabled = YES;
    self.photoScrollView.bounces = NO;
    [self.view addSubview:self.photoScrollView];
    
    NSArray *photoArr = @[@"u=3808451166,1723806820&fm=23&gp=0", @"u=1019182931,1402276621&fm=23&gp=0",@"u=1712427375,1304261470&fm=23&gp=0", @"u=2019074505,523552158&fm=23&gp=0", @"u=2216889308,3751754546&fm=23&gp=0", @"u=2301975825,1085041863&fm=23&gp=0", @"u=2427941702,1013456056&fm=23&gp=0", @"u=3808451166,1723806820&fm=23&gp=0"];
    for (NSInteger i = 0; i < photoArr.count - 1; i++) {
        self.smallScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(i * WIDTH, 0, WIDTH, HEIGHT)];
        self.smallScrollView.delegate = self;
        self.smallScrollView.minimumZoomScale = 0.5;
        self.smallScrollView.maximumZoomScale = 2;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        UIImage *image = [UIImage imageNamed:photoArr[i + 1]];
        [imageView setImage:image];
        [self.smallScrollView addSubview:imageView];
        [self.photoScrollView addSubview:self.smallScrollView];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (self.photoScrollView.contentOffset.x == 0 * WIDTH) {
        self.photoScrollView.contentOffset = CGPointMake(7 * WIDTH, 0);
    }
    //    if (self.photoScrollView.contentOffset.x == 0) {
    //        self.photoScrollView.contentOffset =CGPointMake(7 * WIDTH, 0);
    //    }
    NSLog(@"%f", self.photoScrollView.contentOffset.x);
}


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return [scrollView.subviews firstObject];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
